import 'package:easy_debounce/easy_debounce.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:github_client_app/posts/bloc/post_bloc.dart';
import 'package:github_client_app/posts/view/posts_list.dart';
import 'package:http/http.dart' as http;

class PostsPage extends StatelessWidget {
  const PostsPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    print("PostsPage created");

    return Scaffold(
      appBar: AppBar(
        title: const Text("title"),
      ),
      body: BlocProvider(
        create: (context) {
          return PostBloc(httpClient: http.Client());
        },
        child: Builder(builder: (context) {
          context.read<PostBloc>().add(PostFetched());
          print("object created");
          return InkWell(
              onTap: () {
                context.read<PostBloc>().add(PostInserted());
              },
              child: const PostsList());
        }),
      ),
      // floatingActionButton: FloatingActionButton(
      //   onPressed: () {
      //     context.read<PostBloc>().add(PostInserted());
      //   },
      //   child: Text("o"),
      // ),
    );
  }
}
